package com.academico.web.servlet.disciplina;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.academico.dao.DisciplinaDAO;
import com.academico.model.Disciplina;
import com.academico.util.Util;
import com.academico.web.servlet.BaseServlet;

public class ChangeStatusMatriculaServlet extends BaseServlet {

	private static final long serialVersionUID = 256149893197190730L;

	@Override
	public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		String event = request.getParameter("event");
		Integer codigoDisciplina = Util.convertStringToInteger(request.getParameter("codigoDisciplina"));	
		
		Disciplina disciplina = new Disciplina();
		disciplina.setCodigoDisciplina(codigoDisciplina);

		if("active".equals(event)){
			disciplina.setSituacaoDisciplina(Disciplina.SituacaoDisciplina.ATIVA);
		}
		if("inactive".equals(event)){
			disciplina.setSituacaoDisciplina(Disciplina.SituacaoDisciplina.INATIVA);
		}

		DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
		disciplinaDAO.update(disciplina);
		
		forward("disciplina", request, response);
	}

}
